package com.codeoss.framework.view.parser.store;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import com.codeoss.framework.view.component.Component;
import com.codeoss.framework.view.parser.IComponentParser;
import com.codeoss.framework.view.parser.IParseContext;
import com.fasterxml.jackson.databind.node.ObjectNode;

@Service
public class ComponentParserStore implements IComponentParserStore,ApplicationContextAware{
	private ApplicationContext applicationContext;
	@Override
	public IComponentParser getComponentParser(IParseContext parseContext,ObjectNode objectNode) {
		String type=objectNode.get("type").asText();
		IComponentParser componentParser= (IComponentParser)applicationContext.getBean(type+"Parser");;
		return componentParser;
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		// TODO Auto-generated method stub
		this.applicationContext=applicationContext;
	}

	@Override
	public IComponentParser getComponentParser(IParseContext parseContext, Component component) {
		// TODO Auto-generated method stub
		String type=component.getType();
		IComponentParser componentParser= (IComponentParser)applicationContext.getBean(type+"Parser");;
		return componentParser;
	}
}
